package com.shiku.imserver.common.hander;

import com.shiku.imserver.common.annotation.MessageCommandAnnotation;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public abstract class AbstractMessageHandler implements IMessageHandler {
    private Map<Short, Method> handlerMethods;

    public AbstractMessageHandler() {
        init();
    }

    public Map<Short, Method> getHandlerMethods() {
        return this.handlerMethods;
    }

    public void setHandlerMethods(Map<Short, Method> handlerMethods2) {
        this.handlerMethods = handlerMethods2;
    }

    public void init() {
        MessageCommandAnnotation messageCommandAnnotation;
        this.handlerMethods = new ConcurrentHashMap();
        Method[] methods = getClass().getMethods();
        for (Method method : methods) {
            if (method.isAnnotationPresent(MessageCommandAnnotation.class) && (messageCommandAnnotation = (MessageCommandAnnotation) method.getAnnotation(MessageCommandAnnotation.class)) != null) {
                this.handlerMethods.put(Short.valueOf(messageCommandAnnotation.command()), method);
            }
        }
    }

    public Method getMessageHandler(short command) {
        return this.handlerMethods.get(Short.valueOf(command));
    }
}
